package com.FindMyStuff.Model;

public enum UserRole {
	Admin("a"), User("u");
	
	/**
	 * Holds the Enum Value
	 */
	private String value;
	
	/**
	 * Private Constructor to store the enum value
	 * @param string
	 */
	private UserRole(String string)
	{
		value = string;
	}
	
	/**
	 * Creates a String of the enum 
	 */
	public String toString() {
		String res = "";
	       switch (this) {
	         case Admin:
	        	 res = value;
	        	 break;
	         case User:
	        	 res = value;
	        	 break;
	        }
		return res;
	 }
	
	/**
	 * Converts string into an enum 
	 * @param string value to convert
	 * @return converted enum
	 */
	public static UserRole convertToRole(String string)
	{
		if(string.equals("a"))
		{
			return Admin;
		}
		else 
		{
			return User;
		}
		
	}

	/**
	 * Converts the string into the UserRole representation 
	 * @param string to convert
	 * @return UserRole representation of the string
	 */
	public static UserRole convertStringtoRole(String string) {
		if(string.equals("Admin"))
		{
			return Admin;
		}
		else if(string.equals("User"))
		{
			return User;
		}
		return null;
	}
}
